/**
 * @title: R2dbcConfiguration
 * @projectName mscloud
 * @Description TODO
 * @Author
 * @Date 2022/2/21 15:28
 */
package com.atguigu.springcloud.cloudsentinelgatewaydevelop.config;

import io.r2dbc.spi.ConnectionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
import org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager;
import org.springframework.transaction.ReactiveTransactionManager;

import javax.annotation.Resource;

@Configuration
public class R2dbcConfiguration extends AbstractR2dbcConfiguration {

    //private final ConnectionFactory connectionFactory;
    @Resource
    private ConnectionFactory connectionFactory;

    //public R2dbcConfiguration(@Qualifier("connectionFactory") ConnectionFactory connectionFactory) {
    //    this.connectionFactory = connectionFactory;
    //}

    @Override
    public ConnectionFactory connectionFactory() {
        return this.connectionFactory;
    }

    @Bean
    ReactiveTransactionManager transactionManager(@Qualifier("connectionFactory") ConnectionFactory connectionFactory) {
        return new R2dbcTransactionManager(connectionFactory);
    }
}

